package com.itheima.d09_collections;

import java.util.*;

/**
 * 目标：了解工具类Collections常用方法
 */
public class Test {

    public static void main(String[] args) {
        //1.批量添加数据到集合中
        Set<String> set = new HashSet<>();

        Collections.addAll(set, "张三", "李四", "王五", "赵六", "田七");

        System.out.println( set );

        //2.打乱集合中数据的顺序
        List<String> list = new ArrayList<>();
        Collections.addAll(list, "张三", "李四", "王五", "赵六", "田七");
        System.out.println("乱序前："+ list);

        //打乱集合中数据的顺序
        Collections.shuffle(list);

        System.out.println("乱序后：" + list);


        //3.对集合数据进行排序：数值型集合/字符串集合
        List< Integer> nums = new ArrayList<>();
        Collections.addAll(nums, 1, 5, 3, 9, 2, 7, 4, 6, 8);

        //排序
        Collections.sort(nums);

        System.out.println("排序后：" + nums);

        //4.对集合数据进行排序：自定义实体对象集合
        List<Dog> dogs = new ArrayList<>();
        Collections.addAll(dogs,
                new Dog("旺财", 5),
                new Dog("小黄", 3),
                new Dog("小花", 1),
                new Dog("小黑", 7));

        Collections.sort(dogs, (c,d)->c.getAge()-d.getAge());

        //打印
        dogs.forEach(System.out::println);


        //5.统计集合中的最大值
        Integer max = Collections.max(nums);
        System.out.println( "max="+max);


        Dog maxDog = Collections.min(dogs, (d1, d2) -> d1.getAge() - d2.getAge());
        System.out.println( "maxDog=" +maxDog);


        //6.反转集合中的数据
        System.out.println("反转前的集合："+nums);
        Collections.reverse(nums);
        System.out.println("反转后的集合："+nums);
    }
}













